//道具管理类用来管理生成的各种道具
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止

module py2Obj {
	/**本地地图上所有道具 */
	export class PropManager extends basicObj {


		/** 用来存储所有的道具*/
		public allProps: basicProp[] = [];
		public m_props: basicProp[] = [];
		public m_props1: basicProp[] = [];
		public one2: number = 0;

		public arr: number[] = [];
		public pointArr: egret.Point[] = [];//随机位置
		//玩家加分
		public static twoIce: any[] = [];
		public static twoProp: any[] = [];

		public constructor(world: any, gamePanle: any, romveSkins: any) {
			super(world, gamePanle, romveSkins);
		}
		public putPorpxinshou(tprop) {




			//	tprop.setPostion(x, y);
			//this.pointArr.splice(n, 1);

		}
		public putPorp(tprop) {
			if (tprop.objkind == 400) {
				if (this.pointArr.length <= 0) {
					for (var i = 1; i <= 5; i++) {
						for (var j = 1; j <= 5; j++) {
							var x = (GameData.stageWidth / 5 * i) - 30;
							var y = (GameData.stageHeight - 200) / 5 * j - 200;
							if (y < 100) { y = 100 }; if (y > 600) { y = 600 };
							var p = new egret.Point(x, y);
							this.pointArr.push(p);
						}
					}
				}
				var n = Math.floor(Math.random() * this.pointArr.length);
				tprop.setPostion(this.pointArr[n].x, this.pointArr[n].y);
				this.pointArr.splice(n, 1);
			}
			//body.angle = (-Math.random() * Math.PI / 4) + (Math.random() * Math.PI / 4);
		}
		public putProp2(tprop) {

			if (this.pointArr.length <= 0) {
				for (var i = 1; i <= 5; i++) {
					for (var j = 1; j <= 5; j++) {
						var x = (GameData.stageWidth / 5 * i) - 30;
						var y = (GameData.stageHeight - 200) / 5 * j;//200
						if (y < 100) { y = 100 }; if (y > 600) { y = 600 };
						var p = new egret.Point(x, y);
						this.pointArr.push(p);
					}
				}
			}
			var n = Math.floor(Math.random() * this.pointArr.length);
			tprop.setPostion(this.pointArr[n].x, this.pointArr[n].y);
			this.pointArr.splice(n, 1);

		}
		public removePorp(ba: basicProp) {
			var index = this.m_props.indexOf(ba);
			if (index > -1) {
				this.m_props.splice(index, 1);
			}
			else {
				return;
			}
			this.m_removeSkins.push(ba.getBody().userData.skin);
			this.m_world.removeBodys.push(ba.getBody());

			if (PropManager.twoIce.length > 0) {

				return;
			}
			else {
				//	this.createProp();//原来的
				//this.createPropXinShou();//新手引导

			}

		}
		public removePorp1(ba: basicProp) {
			var index = this.m_props1.indexOf(ba);
			if (index > -1) {
				this.m_props1.splice(index, 1);
			}
			else {

				return;
			}
			this.m_removeSkins.push(ba.getBody().userData.skin);
			this.m_world.removeBodys.push(ba.getBody());
			if (PropManager.twoProp.length > 0) {
				return;
			}
			else {
				//	this.createProp();//原来的
				//this.createPropXinShou();//新手引导
			}


		}
		//根据玩家的等级来创建一个或者多个道具


		//新手引导
		public createPropXinShou() {
			if (GameControl.GameControlSole.count < 50) {

				var prop;
				var shuzu: number[] = [];
				shuzu = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
				//var one = Math.floor(Math.random() * shuzu.length);
				if (this.one2 < 8) {
					this.one2 += 1;
					var count2 = shuzu[this.one2];
					if (count2 == 1 || count2 == 4 || count2 == 8) {//激光道具
						prop = new laserProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;

						this.putProp2(prop);
						prop.setPostion(500, 500);

						this.m_props1.push(prop);
						this.allProps.push(prop);
					} else if (count2 == 5) {//放大道具
						prop = new magnify(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;

						//	this.putProp2(prop);
						//	this.putPorpxinshou(prop);
						prop.setPostion(450, 450);
						this.m_props1.push(prop);
						this.allProps.push(prop);
					} else if (count2 == 3) {//爆炸道具
						prop = new BoomProp(this.m_world, this.m_gamePanle, this.m_removeSkins);

						prop.init();
						prop.m_propManger = this;
						prop.setPostion(200, 150);
						//this.putProp2(prop);
						//	this.putPorpxinshou(prop);

						this.m_props1.push(prop);
						this.allProps.push(prop);
					}
					else if (count2 == 7) {//重力道具
						prop = new gravityProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						//this.putProp2(prop);
						//this.putPorpxinshou(prop);
						prop.setPostion(500, 200);
						this.m_props1.push(prop);
						this.allProps.push(prop);
					} else if (count2 == 6) {//触发道具
						prop = new strikeProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						//this.putProp2(prop);
						//	this.putPorpxinshou(prop);
						prop.setPostion(230, 400);
						this.m_props1.push(prop);
						this.allProps.push(prop);
					}
					else if (count2 == 2) {//金币

						var prop;
						prop = new IceProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						prop.setPostion(200,300);//333333
						//this.putPorp(prop);
						this.m_props.push(prop);
						this.allProps.push(prop);
						 
						 
					}
				}
				else {
					this.createProp();
				}
			}
		}//新手引导


		public createProp() {
			var suiji = Math.floor(Math.random() * 10);
			if (GameControl.GameControlSole.count < 50) {

				var prop;
				var shuzu: number[] = [];
				shuzu = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
				var one = Math.floor(Math.random() * shuzu.length);
				var count2 = shuzu[one];


				console.log("Count:" + count);
				if (count2 == 1) {
					prop = new laserProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				} else if (count2 == 3) {
					prop = new magnify(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				} else if (count2 == 5) {
					prop = new BoomProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				}
				else if (count2 == 7) {
					prop = new gravityProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				} else if (count2 == 9) {
					prop = new strikeProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				}
				else {

					var prop;
					prop = new IceProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putPorp(prop);
					this.m_props.push(prop);
					this.allProps.push(prop);

				}
			}
			else if (GameControl.GameControlSole.count >= 50 && GameControl.GameControlSole.count < 80) {

				var prop;
				var shuzu: number[] = [];
				shuzu = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
				var one = Math.floor(Math.random() * shuzu.length);
				var count1 = shuzu[one];

				if (count1 == 1) {
					prop = new laserProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				} else if (count1 == 3) {
					prop = new magnify(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				} else if (count1 == 5) {
					prop = new BoomProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				}
				else if (count1 == 7) {
					prop = new gravityProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				} else if (count1 == 9) {
					prop = new strikeProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putProp2(prop);
					this.m_props1.push(prop);
					this.allProps.push(prop);
				}
				else {
					var prop;
					prop = new IceProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
					prop.init();
					prop.m_propManger = this;
					this.putPorp(prop);
					this.m_props.push(prop);
					this.allProps.push(prop);
				}



			}


			if (GameControl.GameControlSole.count >= 80) {
				var num777 = Math.floor(Math.random() * 10);

				PropManager.twoIce.splice(0, PropManager.twoIce.length);

				if (num777 < 8) {
					//if (level == 1) {//创建普通道具
					var count: number;

					if (PropManager.twoIce.length < 2) {

						var prop;
						prop = new IceProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						this.putPorp(prop);
						this.m_props.push(prop);
						this.allProps.push(prop);
						PropManager.twoIce.push(prop);

						var prop1;
						prop1 = new IceProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop1.init();
						prop1.m_propManger = this;
						this.putPorp(prop1);
						this.m_props.push(prop1);
						this.allProps.push(prop1);
						PropManager.twoIce.push(prop1);
						var aa = PropManager.twoIce;
					}
				}
				else if (num777 >= 8) {

					var prop;
					var shuzu: number[] = [];
					shuzu = [1, 3, 5, 7, 9];
					var one = Math.floor(Math.random() * shuzu.length);
					var count11 = shuzu[one];
					if (count11 == 1) {
						prop = new laserProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						this.putProp2(prop);
						this.m_props1.push(prop);
						this.allProps.push(prop);
						PropManager.twoProp.push(prop);
					} else if (count11 == 3) {
						prop = new magnify(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						this.putProp2(prop);
						this.m_props1.push(prop);
						this.allProps.push(prop);
						PropManager.twoProp.push(prop);
					} else if (count11 == 5) {
						prop = new BoomProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						this.putProp2(prop);
						this.m_props1.push(prop);
						this.allProps.push(prop);
						PropManager.twoProp.push(prop);
					}
					else if (count11 == 7) {
						prop = new gravityProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						this.putProp2(prop);
						this.m_props1.push(prop);
						this.allProps.push(prop);
						PropManager.twoProp.push(prop);
					} else if (count11 == 9) {
						prop = new strikeProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop.init();
						prop.m_propManger = this;
						this.putProp2(prop);
						this.m_props1.push(prop);
						this.allProps.push(prop);
						PropManager.twoProp.push(prop);
					}

					var prop1;
					var shuzu: number[] = [];
					shuzu = [1, 3, 5, 7, 9];
					var two = Math.floor(Math.random() * shuzu.length);
					var count12 = shuzu[two];
					if (count12 == 1) {
						prop1 = new laserProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop1.init();
						prop1.m_propManger = this;
						this.putProp2(prop1);
						this.m_props1.push(prop1);
						this.allProps.push(prop1);
						PropManager.twoProp.push(prop1);
					} else if (count12 == 3) {
						prop1 = new magnify(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop1.init();
						prop1.m_propManger = this;
						this.putProp2(prop1);
						this.m_props1.push(prop1);
						this.allProps.push(prop1);
						PropManager.twoProp.push(prop1);
					} else if (count12 == 5) {
						prop1 = new BoomProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop1.init();
						prop1.m_propManger = this;
						this.putProp2(prop1);
						this.m_props1.push(prop1);
						this.allProps.push(prop1);
						PropManager.twoProp.push(prop1);
					}
					else if (count12 == 7) {
						prop1 = new gravityProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop1.init();
						prop1.m_propManger = this;
						this.putProp2(prop1);
						this.m_props1.push(prop1);
						this.allProps.push(prop1);
						PropManager.twoProp.push(prop1);
					} else if (count12 == 9) {
						prop1 = new strikeProp(this.m_world, this.m_gamePanle, this.m_removeSkins);
						prop1.init();
						prop1.m_propManger = this;
						this.putProp2(prop1);
						this.m_props1.push(prop1);
						this.allProps.push(prop1);
						PropManager.twoProp.push(prop1);
					}
				}
			}
		}
		public init() {
			super.init();
		}
		public createMyRigidbody(): p2.Body {
			return null;
		}
	}
}